package cloud.xlh.event_pub_and_listen.listener;

import cloud.xlh.event_pub_and_listen.event.MountSettingEvent;
import cloud.xlh.service.file.service.RemoteFileService;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/8/5 22:25
 * @ Description:
 */
@Component
public class MountSettingEventListener implements ApplicationListener<MountSettingEvent> {
    @Override
    public void onApplicationEvent(MountSettingEvent event) {
        String beanName = event.getBeanName();
        RemoteFileService remoteFileService = SpringUtil.getBean(beanName);
        Map<String, String> parmaMap = (HashMap<String, String>) event.getParma();
        ConcurrentHashMap<String, String> mountDirMpMap = remoteFileService.getMountDirMpMap();
        if (!"1".equals(parmaMap.get("settingType"))) {
            mountDirMpMap.put(parmaMap.get("mpLocalDirPath"), parmaMap.get("mpRemoteDirPath"));
        } else {
            mountDirMpMap.remove(parmaMap.get("mpLocalDirPath"));
        }
    }
}
